﻿using UnityEngine;
using Watermelon;

public abstract class Upgrade<T> : BaseUpgrade where T : BaseUpgradeStage
{
    [SerializeField]
    protected T[] upgrades;
    public override BaseUpgradeStage[] Upgrades => upgrades;

    public T GetCurrentStage()
    {
        if(upgrades.IsInRange(upgradeLevel))
            return upgrades[upgradeLevel];

        Debug.LogError("[Perks]: Perk level is out of range!");

        return null;
    }

    public override void UpgradeStage()
    {
        if (upgrades.IsInRange(upgradeLevel + 1))
        {
            upgradeLevel += 1;

            UpgradesEventsHandler.Events.OnUpgraded(upgradeType, this);
        }
    }


    [Button("Info")]
    public void TestInfo()
    {
        Debug.Log(upgradeType + ": " + upgradeLevel);
    }

    [Button("Upgrade")]
    public void TestUpgrade()
    {
        UpgradeStage();
    }

    [Button("Reset")]
    public void ResetUpgrade()
    {
        upgradeLevel = 0;

        UpgradesEventsHandler.Events.OnUpgraded(upgradeType, this);
    }
}